package framework;

import org.newdawn.slick.GameContainer;

import framework.attack.BasicAttack;
import framework.attack.Teleport;
import framework.collision.AttackCollisionManager;

public class BasicAttackGetter implements AttackGetter {
	
	protected AttackCollisionManager collision;
	
	protected Teleport teleport; 
	
	protected BasicAttack<?> aAttack;
	
	protected BasicAttack<?> xAttack;
	
	protected BasicAttack<?> yAttack;
	
	protected BasicAttack<?> bAttack;
	
	protected BasicAttack<?> aAttackJump;
	
	protected BasicAttack<?> xAttackJump;
	
	protected BasicAttack<?> yAttackJump;
	
	protected BasicAttack<?> bAttackJump;
	
	protected BasicFighter fighter;
	
	public BasicAttackGetter(BasicFighter fighter) {
		this.fighter = fighter;
		aAttack =  new BasicAttack<>(fighter);
		aAttackJump = new BasicAttack<>(fighter);
		bAttack = new BasicAttack<>(fighter);
	    bAttackJump = new BasicAttack<>(fighter);
		xAttack = new Teleport(fighter);
		xAttackJump = new Teleport(fighter);
		yAttack = new BasicAttack<>(fighter);
		yAttackJump = new BasicAttack<>(fighter);
		teleport = new Teleport(fighter);
	}
	
	public void init(GameContainer gc) {
		float scale = Util.getScale(gc);
		aAttack.setScale(scale);
		aAttackJump.setScale(scale);
		bAttack.setScale(scale);
		bAttackJump.setScale(scale);
		xAttack.setScale(scale);
		xAttackJump.setScale(scale);
		yAttack.setScale(scale);
		yAttackJump.setScale(scale);
	}

	@Override
	public BasicAttack<?> getAttack(Controls c) {
		BasicAttack<?> attack = null;
		switch(c) {
		case A_P1 : case A_P2 :
			attack = fighter.isJumping() ? aAttackJump : aAttack;
			break;
		case X_P1 : case X_P2 :
			attack = fighter.isJumping() ? xAttackJump : xAttack;
			break;
		case Y_P1 : case Y_P2 :
			attack = fighter.isJumping() ? yAttackJump : yAttack;
			break;
		case B_P1 : case B_P2 :
			attack = fighter.isJumping() ? bAttackJump : bAttack;
			break;
		case TELEPORT_P1 : case TELEPORT_P2 :
			attack = teleport;
			break;
		default :
		    break;
		}
		attack.setAttackCollisionManager(collision);
		return attack;
	}

	@Override
	public void setAttackCollision(AttackCollisionManager collision) {
		this.collision = collision;
		aAttack.setAttackCollisionManager(collision);
		bAttack.setAttackCollisionManager(collision);
		xAttack.setAttackCollisionManager(collision);
		yAttack.setAttackCollisionManager(collision);
		aAttackJump.setAttackCollisionManager(collision);
		bAttackJump.setAttackCollisionManager(collision);
		xAttackJump.setAttackCollisionManager(collision);
		yAttackJump.setAttackCollisionManager(collision);
		teleport.setAttackCollisionManager(collision);
	}
}
